package com.getword.web.controller;


import com.getword.domain.Article;
import com.getword.security.SUser;
import com.getword.service.SearchService;
import com.getword.web.model.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/search")
public class ApiSearchController {
    @Autowired
    private SearchService searchService;

    // 文章查询，根据文章的标题、文章keywords查询
    @GetMapping("/article")
    public Result article(int page, int size, String key, HttpServletRequest request) {
        Result result = searchService.searchArticle(PageRequest.of(page, size), key);
        result.setMsg(key);
        return result;
    }

    // 文章video，根据文章的标题、文章keywords查询
    @GetMapping("/video")
    public Result video(int page, int size, String key, HttpServletRequest request) {
        Result result = searchService.searchVideo(PageRequest.of(page, size), key);
        result.setMsg(key);
        return result;
    }
}
